package com.sebastian.studies.ch6;

import java.util.Scanner;

public class Excercise_6_1 {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		System.out.println("Enter some (5) numbers to an array");
		int[] array = new int[5];

		for(int i = 0; i <= 4; i++) {
			System.out.println("Enter an integer: ");
			array[i] = input.nextInt();
		}

		System.out.print("The original array is: ");
		for(int i = 0; i <= 4; i++) {
			System.out.print(array[i] + " ");
		}

		System.out.print("\nThe reversed one: ");
		reversingArray(array);
		System.out.print("\nThe reversed one with new function: ");
		reversingArrayNew(array);

		System.out.print("\nIncreas array elements by given factor. Enter a factor: ");
		int factor = input.nextInt();
		reversingArrayForeachLoop(array, factor);

		input.close();
	}

	public static void reversingArray(int[] myArray) {
		int temp = myArray[0];
		for(int i = 1; i < myArray.length; i++) {
			myArray[i -1] = myArray[i];
		}
		myArray[myArray.length - 1] = temp;
		
		for (int i = 0; i < myArray.length; i++) {
			System.out.print(myArray[i] + " ");
		}
		myArray[myArray.length - 1] = temp;
	}
	
	public static void reversingArrayForeachLoop(int[] myArray, int factor) {
		for (int i : myArray) {
			System.out.println(myArray[i - 1] + factor);
		}
	}
	
	public static void reversingArrayNew(int[] myArray) {
		for(int i = myArray.length; i > 0; i--) {
			System.out.print(myArray[i - 1] + " ");
		}
	}
}
